<%- include('header') %>
<div class="wrapper">
  <% if(articles.length > 0) { %>
  <ul class="list article-list">
    <% articles.forEach((item) => { %>
      <li class="list-item">
        <div class="list-item-header">
          <img src="/img/avatar/<%= item.avatar %>" class="avatar" alt="avatar">
          <div class="title"><a href="/articles/<%= item.id %>"><%= item.title %></a></div>
        </div>
        <div class="list-item-body markdown">
          <%- item.markdown ? item.markdown : item.content %>
          <a href="/articles/<%= item.id %>" class="read">阅读全文</a>
        </div>
        <div class="list-item-footer">
          <div>
            <span>作者：<%= item.name %></span>
            <span>评论数：<%= item.comment %></span>
            <span>浏览量：<%= item.pv %></span>
          </div>
          <div>
            <span><%= item.time %></span>
          </div>
        </div>
      </li>
    <% }) %>
  </ul>
  <% } else { %>
    <p class="tips">暂时没有文章，快去发表吧！</p>
  <% } %>
</div>
<div id="pagination"></div>
<script>
$(function() {
  const type = '<%= type %>'
  const author = type === 'self' && '<%= session.user %>'
  const articleCount = '<%= articleCount %>'
  const currPage = '<%= page %>'
  const pageSize = '<%= size %>'

  $('#pagination').sPage({
    page: currPage,
    pageSize: pageSize,
    totalText: `共 {total} 条`,
    showTotal: true,
    showSkip: articleCount > 100 ? true : false,
    total: articleCount,
    backFun: (page) => {
      window.location.href = type === 'self' ? `/articles?author=${author}&page=${page}` : `/articles?&page=${page}`
    }
  })

})
</script>
<% include('footer') %>